package com.fzz.learning_forum.controller;

import com.fzz.learning_forum.domain.Article;
import com.fzz.learning_forum.domain.Reply;
import com.fzz.learning_forum.service.ArticleService;
import com.fzz.learning_forum.service.ReplyService;
import com.fzz.learning_forum.serviceImpl.ArticleServiceImpl;
import com.fzz.learning_forum.serviceImpl.ReplyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class ReplyController {


    @Autowired
    private ReplyService replyService=new ReplyServiceImpl();

    @Autowired
    private ArticleService articleService=new ArticleServiceImpl();


    //发表回复
    @RequestMapping(value = "/user/publishReply")
    @ResponseBody
    public String publishReply(Reply reply)
    {
        Integer rows = replyService.publishReply(reply);
        if(rows>0)
        {
            try {
                Article article = articleService.selectArticleDetail(reply.getArticle_id());
                Integer hit = article.getHit();
                hit+=1;
                article.setHit(hit);
                articleService.updateArticleHit(reply.getArticle_id(),hit);
            }
            catch (Exception e)
            {
                System.out.println(e.getCause());
            }
            return "OK";
        }
        return "NO";
    }

}
